const app = getApp()

import { TMapWX } from '../../libs/TMapWX.js';
import { formatTime } from '../../utils/util';

let TMap = new TMapWX("DPVBZ-NTQ3J-6NGFJ-FNLI7-GYGP6-NRFO4");

Page({
	data: {
		city: "成都市",
		nowTemp: '', // 当前温度
		nowWeather: '', // 当前天气
		dressIndex: '', // 穿衣指数
		exerciseIndex: '', // 锻炼指数
		washIndex: '', // 洗车指数
		travelIndex: '', // 出行指数
		todayDate: '', // 今天时间
		todayTempScop: '', // 今天的温度范围
		weatherImage: 'sunny', // 背景图片名
		modifycityMode : false
	},
	onLoad() {
		TMap.weather({
			success : ({data}) => {
				let todayDetial =data.forecast_24h[0];
				let curDetial = data.forecast_1h[0];
				let index = data.index;
				this.setData({
					nowTemp:curDetial.degree,
					nowWeather:curDetial.weather,
					dressIndex:index.clothes.info,
					exerciseIndex:index.sports.info,
					washIndex:index.carwash.info,
					travelIndex:index.tourism.info,
					todayDate:formatTime(new Date()),
					todayTempScop:'今日' + todayDetial.min_degree + '°~' + todayDetial.max_degree + '°'
				})
			},
		})
	},
	changeCityMode: function () {
		this.setData({
			modifycityMode: !this.data.modifycityMode
		})
	},
})
